package com.tutu.controller.backend;

import com.tutu.controller.common.CommonController;
import com.tutu.service.AlarmMessageService;
import com.tutu.service.CompanyService;
import com.tutu.service.DeviceService;
import com.tutu.service.UserService;
import com.tutu.utils.WxMsgPushUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;

/**
 * 微信公众号管理
 */
@Controller
@RequestMapping(value = "wx")
public class WechatController extends CommonController {

    @Autowired
    AlarmMessageService alarmMessageService;

    @Autowired
    UserService userService;

    @Autowired
    DeviceService deviceService;

    @Autowired
    CompanyService companyService;

    // 获取签名配置
    @RequestMapping("/signature")
    @ResponseBody
    public Map<String, String> getSignature(String url) {
        return WxMsgPushUtil.generateSignature(url);
    }

    // 数据中心 - 数据监控
    @RequestMapping("/project/index")
    public String projectIndex(HttpServletRequest request, Model model) {
        model.addAttribute("wxUserId", userService.getWxUserInfoByCode(request.getParameter("code")).getId());

        return "wechat/project/initPage";
    }

    @RequestMapping("/project/main")
    public String projectMainPage() {
        return "wechat/project/mainPage";
    }

    @RequestMapping("/project/device")
    public String projectDevicePage() {
        return "wechat/project/devicePage";
    }

    @RequestMapping("/project/data")
    public String projectDataPage() {
        return "wechat/project/dataPage";
    }

    // 数据中心 - 历史消息
    @RequestMapping("/project/message")
    public String projectMessage(HttpServletRequest request, Model model) {
        model.addAttribute("wxUserId", userService.getWxUserInfoByCode(request.getParameter("code")).getId());

        return "wechat/project/message";
    }

    // 个人中心
    @RequestMapping("/center/index")
    public String centerIndex(HttpServletRequest request, Model model) {
        model.addAttribute("wxUserId", userService.getWxUserInfoByCode(request.getParameter("code")).getId());

        return "wechat/center/index";
    }

    @RequestMapping("/center/selectCompany")
    public String selectCompany() {
        return "wechat/center/selectCompany";
    }

    @RequestMapping("/center/user")
    public String centerUser() {
        return "wechat/center/user";
    }

    @RequestMapping("/center/device")
    public String centerDevice() {
        return "wechat/center/device";
    }

    @RequestMapping("/center/deviceSwitch")
    public String centerDeviceSwitch() {
        return "wechat/center/deviceSwitch";
    }

    @RequestMapping("/center/alarmRule")
    public String centerAlarmRule() {
        return "wechat/center/alarmRule";
    }

    @RequestMapping("/center/alarmRuleInfo")
    public String centerAlarmRuleInfo() {
        return "wechat/center/alarmRuleInfo";
    }

    @RequestMapping("/center/company")
    public String centerCompany() {
        return "wechat/center/company";
    }

    @RequestMapping("/center/setting")
    public String centerSetting() {
        return "wechat/center/setting";
    }

    @RequestMapping("/center/personInfo")
    public String centerPersonInfo() {
        return "wechat/center/personInfo";
    }

    @RequestMapping("/center/completeInfo")
    public String centerCompleteInfo(Model model, Integer companyId) {
        model.addAttribute("companyId", companyId);

        return "wechat/center/completeInfo";
    }

    @RequestMapping("/center/contactUs")
    public String contactUs() {
        return "wechat/center/feedback";
    }

    @RequestMapping("/center/invitation")
    public String centerInvitation() {
        return "wechat/center/invitation";
    }

    @RequestMapping(value = "/showQrCodeImg")
    @ResponseBody
    public void showQrCodeImg(HttpServletResponse response, Integer companyId) {
        companyService.createQRCode(response, companyId);
    }
}
